package vip.source.pattern.part20.improve;

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import vip.source.pattern.part20.improve.impl.MJCouponDiscount;
import vip.source.pattern.part20.improve.impl.NYGCouponDiscount;
import vip.source.pattern.part20.improve.impl.ZJCouponDiscount;
import vip.source.pattern.part20.improve.impl.ZKCouponDiscount;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 测试策略模式
 * @Author: zy
 **/
public class UnitTest {
    private Logger logger = LoggerFactory.getLogger(UnitTest.class);

    @Test
    public void test_zj() {
        // 直减；100-10，商品100元
        StrategyContext<Double> strategyContext = new StrategyContext<Double>(new ZJCouponDiscount());
        BigDecimal discountAmount = strategyContext.discountAmount(10D, new BigDecimal(100));
        logger.info("测试结果：直减优惠后金额 {}", discountAmount);
    }

    @Test
    public void test_mj() {
        // 满100减10，商品100元
        StrategyContext<Map<String, String>> strategyContext =
                new StrategyContext<Map<String, String>>(new MJCouponDiscount());
        Map<String, String> mapReq = new HashMap<String, String>();
        mapReq.put("x", "100");
        mapReq.put("n", "10");
        BigDecimal discountAmount = strategyContext.discountAmount(mapReq, new BigDecimal(100));
        logger.info("测试结果：满减优惠后金额 {}", discountAmount);
    }


    @Test
    public void test_zk() {
        // 折扣9折，商品100元
        StrategyContext<Double> strategyContext = new StrategyContext<Double>(new ZKCouponDiscount());
        BigDecimal discountAmount = strategyContext.discountAmount(0.9D, new BigDecimal(100));
        logger.info("测试结果：折扣9折后金额 {}", discountAmount);
    }

    @Test
    public void test_nyg() {
        // n元购；100-10，商品100元
        StrategyContext<Double> strategyContext = new StrategyContext<Double>(new NYGCouponDiscount());
        BigDecimal discountAmount = strategyContext.discountAmount(90D, new BigDecimal(100));
        logger.info("测试结果：n元购优惠后金额 {}", discountAmount);
    }
}
